<?php

namespace Api\Model;

use Think\Model;

class UserDefaultAvatarModel extends Model {

    /**
     * @name 获取默认头像
     */
    public function getDefaultAvatar() {
        return $this->where("`status`=1")->field('id,name,url')->select();
    }

    /**
     * @name 保存用户头像
     * @param $id
     */
    public function saveDefaultAvatar($userid, $id) {
        $avatar = $this->where("`id`={$id} and `status`=1")->getField('url');
        if ($avatar == false) {
            $this->last_msg('头像不存在！');
            return false;
        }
        $result = M('User')->where("`id`={$userid}")->save(array('avatar' => $avatar));
        if ($result == false) {
            $this->last_msg('头像更新失败！');
            return false;
        }
        return true;
    }

}
